package com.myidis.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.myidis.entity.RightUserGroupRole;
import com.myidis.servlet.RightUserGroupRoleServlet;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/groupRole")
@Api(tags = "用户组包含角色管理接口")
public class RightUserGroupRoleController {
	@Autowired
	private RightUserGroupRoleServlet rightUserGroupRoleServlet;
	
	@ResponseBody
	@ApiOperation("获取当前用户组所有角色的信息")
	@RequestMapping(value="/list",method=RequestMethod.POST)
	public List<RightUserGroupRole> list() {
		return rightUserGroupRoleServlet.all();
	}
	
	@ResponseBody
	@ApiOperation("获取当前用户组一个角色的信息")
	@RequestMapping(value="/entity",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public RightUserGroupRole one(@PathVariable int id) {
		return rightUserGroupRoleServlet.getOne(id);
	}
	
	@ResponseBody
	@ApiOperation("添加一个角色到用户组")
	@RequestMapping(value="/add",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public int add(@RequestBody RightUserGroupRole rightUserGroupRole) {
		return rightUserGroupRoleServlet.insert(rightUserGroupRole);
	}
	
	@ResponseBody
	@ApiOperation("添加一组角色到一个或多个用户组")
	@RequestMapping(value="/addAll",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public int addAll(@RequestBody List<RightUserGroupRole> rightUserGroupRoles) {
		return rightUserGroupRoleServlet.insert(rightUserGroupRoles);
	}
	
	@ResponseBody
	@ApiOperation("修改一条信息")
	@RequestMapping(value="/upd",method=RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
	public int upd(@RequestBody RightUserGroupRole rightUserGroupRole) {
		return rightUserGroupRoleServlet.update(rightUserGroupRole);
	}

	@ResponseBody
	@ApiOperation("删除一条信息")
	@RequestMapping(value="/del",method=RequestMethod.POST)
	public int del(@RequestBody int id) {
		return rightUserGroupRoleServlet.delete(id);
	}
	
	@ResponseBody
	@ApiOperation("删除一组信息")
	@RequestMapping(value="/delAll",method=RequestMethod.POST)
	public int delAll(@RequestBody int[] ids) {
		return rightUserGroupRoleServlet.delete(ids);
	}
}
